$(function () {
    getUserList();
});
/*重置*/
function resetClick(){
    $(".dis-inebl input").val("");
    $("#userState option:selected").val("全部");
    $("#userRole option:selected").val("全部");
    getUserList();
}
/*查询*/
function getUserList(init){
    JY.Model.loading();
	$("#ticktTable tbody").html("");
    var pageNum=$("#baseForm .pageNum").val();
    var pageSize=$("#baseForm .pageSize").val();
	var userName =$("#userName").val().trim();
	var userTel =$("#userTel").val().trim();
	var userState=$("#userState option:selected").val();
    var userRole=$("#userRole option:selected").val();
    if(userState=="全部"){
        userState="";
    }
    if(userRole=="全部"){
        userRole="";
    }
	$.ajax({
		url : jypath + "/user/getUserList",
		type : "post",
		data:{
            "pageNum":pageNum,
            "pageSize":pageSize,
            "nickname":userName,
            "userPhone":userTel,
            "state":userState,
            "type":userRole,
		},
		jsonType : "json",
		success : function(data) {
		    console.log(data)
            var data=data instanceof Object ? data : JSON.parse(data);
            var html="";
            var list=data.obj;
            var results=list.results;
            var pageNum=list.pageNum,
                pageSize=list.pageSize,
                totalRecord=list.totalRecord;
           if(results!=null&&results.length>0){
                var leng=(pageNum-1)*pageSize;//计算序号
                for(var i = 0;i<results.length;i++){
                    var l=results[i];
                    html+="<tr class='tr_color'>";
                    html+="<td class='center ver-m'><label><input type='checkbox' name='ids' value='"+l.userId+"' roleType='"+l.type+"' class='ace' /> <span class='lbl'></span></label></td>";
                    html+="<td class='center'>"+l.nickname+"</td>";
                    html+="<td class='center'>"+l.userPhone+"</td>";
                    if(l.type==1){
                        html+="<td class='center'>医生</td>";
                    }else if(l.type==0){
                        html+="<td class='center'>普通用户</td>";
                    }
                    if(l.registerChannel==null||l.registerChannel==undefined||l.registerChannel==""){
                        html+="<td class='center'>暂无</td>";
                    }else{
                        html+="<td class='center'>"+l.registerChannel+"</td>";
                    }
                    if(l.address==null||l.address==undefined||l.address==""){
                        html+="<td class='center'>暂无</td>";
                    }else{
                        html+="<td class='center'>"+l.address+"</td>";
                    }
                    html+="<td class='center'>"+l.userPoint+"</td>";
                    if(l.state==0){
                        html+="<td class='center'>失效</td>";
                    }else if(l.state==1){
                        html+="<td class='center'>有效</td>";
                    }
                    html+="<td class='center'><a onclick='sendMess("+l.userId+")'>发送消息</a></td>";
                    html+="</tr>";
                }
                $("#ticktTable tbody").append(html);
                JY.Page.setPage("baseForm","pageing",pageSize,pageNum,totalRecord,"getUserList");
            }else{
                html+="<tr><td colspan='8' class='center'>没有相关数据</td></tr>";
                $("#ticktTable tbody").append(html);
                $("#baseForm ul").empty();//清空分页
            }
            JY.Model.loadingClose();
		}
	})
}
function sendMess(userId){
    clearData();
    JY.Model.edit("auForm_check","发送消息",function(){
        var that=$(this);
        if(JY.Validate.form("doctors")){
            if($(".informText").val()==""||$(".informText").val()==null){
                JY.Model.info("请填写发送内容！");
            }else{
                $(".masks").removeClass("hide");
                $.ajax({
                    url : jypath + "/ymUserInfrom/insertUserInformation",
                    type : "post",
                    data:{
                        "userId":userId,
                        "infromTypeId":2,
                        "informText":$(".informText").val(),
                    },
                    jsonType : "json",
                    success : function(data) {
                        that.dialog("close");
                        $(".masks").addClass("hide");
                        if(data.res==1){
                            JY.Model.info("发送成功!");
                        }else{
                            JY.Model.info(data.resMsg);
                        }
                    }
                })
            }
        }
    })
}
function clearData(){
    $("#doctors textarea").val("");
}
